# 这里是注册模块
from django.shortcuts import render
from rest_framework.views import APIView
from .models import User
from rest_framework.response import Response
from rest_framework.generics import CreateAPIView
from . import serializers
# Create your views here.


class UserView(CreateAPIView):
    # 用户注册模块

    # 我们只需要指定一个序列化器,其余的父类都有
    serializer_class = serializers.CreateUserSerializer

class MoblieCountView(APIView):
    # 用于判断手机号是否重复
    def get(self, request, moblie):
        # 使用username作为条件查询满足条件的记录数量
        count = User.objects.filter(moblie=moblie).count()
        # 构造响应数据
        data = {
            'moblie': moblie,
            'count': count
        }
        # 响应数据
        return Response(data)



class UsernameCountView(APIView):
    # 用于判断用户名是否存在
    def get(self, request, username):
        # 使用username作为条件查询满足条件的记录数量
        count = User.objects.filter(username=username).count()
        # 构造响应数据
        data = {
            'username':username,
            'count':count
        }
        # 响应数据
        return Response(data)